
$(document).ready(function(){
    
    if($("#text-promo-list").length > 0)
    $('#text-promo-list').carouFredSel({
        items               : 1,
        direction           : "up",
        scroll : {
            items           : 1,
            fx              : "fade",
            duration        : 500
        },
        auto                : 5000
    });
    
    /* Submenu control */
    
    $('.nav>ul>li').hover(function(){
		$('.submenu').hide();

		if(!$(this).find('.reserve').length > 0 && $('#ui-datepicker-div').length > 0){
			$('#ui-datepicker-div').hide();
		}
        $(this).find('.submenu').show();
        $(this).find('.submenu').stop();
        $(this).find('.submenu').animate({
            opacity: 1.0
        }, 200);        
    });

    $('.nav>ul>li').mouseleave(function() {
    
        if($('#ui-datepicker-div').length > 0)
            if($('.ui-datepicker').css('display') == "block")
                return;
        
        $(this).find('.submenu').stop();
        $(this).find('.submenu').animate({
            opacity: 0.0
        }, 200, function() {
            $(this).hide();
        });
    });
   
    if($("#carousel").length > 0)
        $("#carousel").carouFredSel({
            width	: "100%",
            scroll	: 1,
            auto : 9000,
            prev : "#carousel_prev",
            next : "#carousel_next",
            circular: false,
            scroll : {
                wipe: true
            }
        });
    
    if($(".img_slider").length > 0)
        $(".img_slider").carouFredSel({
            scroll	: {
                items   : 1,
                fx      : "crossfade"
            },
            auto: true
        });
    
    
    $('.main #toggler').click( function() {
        var cp = $('.main #toggler').attr('cp');
        var op = $('.main #toggler').attr('op');
        
        
        if($('.main').hasClass('down'))
        {
            $('.main').removeClass('down').animate({
                bottom: '45px'
            },500, function() {
                $('.main #toggler').text(cp);
            });
        }
        else
        {
            $('.main').addClass('down').animate({
                bottom: '-132px'
            },700, function() {
                $('.main #toggler').text(op);
            });
        }
    });
    
    $('.content #toggler').click( function() {
        var cp = $(this).attr('cp');
        var op = $(this).attr('op');
        if($('.content_wrapper').hasClass('down'))
        {
            $('.content_wrapper').removeClass('down').animate({
                bottom: '46px'
            },500, function() {
                //$('.content_wrapper #toggler').text("CLOSE PANEL");
                $('.content_wrapper #toggler').text(cp);
            });
        }
        else
        {
            $('.content_wrapper').addClass('down').animate({
                bottom: '-234px'
            },700, function() {
                //$('.content_wrapper #toggler').text("OPEN PANEL");
                $('.content_wrapper #toggler').text(op);
            });
        }
    });
    
    //Scrollpane
    $('.scroll').jScrollPane({
        verticalGutter  : '1',
        showArrows: false,
        animateScroll : true
    });
    
    //Handle the hiding
    var mouse_is_inside = false;

    $('.reserve').hover(function(){
        mouse_is_inside=true; 
    }, function(){
        mouse_is_inside=false;
    });

    $(".ui-datepicker").hover( function() {
        mouse_is_inside=true; 
    }, function(){
        mouse_is_inside=false; 
    });
    
    $("body").mouseup(function(){
        if(!mouse_is_inside){
            $('.submenu').animate({
                opacity: 0.0
            }, 200, function() {
                $(this).hide();
            });
        }
    });
    
    $('.contact_form, .contact_form_auto').fancybox({
        width           : 580,
        height          : 610,
        padding 	: 0,
        fitToView	: false,
        autoSize	: false,
        closeClick	: false,
        openEffect	: 'none',
        closeEffect	: 'none',
        scrolling	: 'no',
        type            : 'iframe',
		helpers: { 
			title: null
		}
    });
    
    
    
    
    
    
    
    
    
    
    
    
});


$(window).load(function(){
    
    //Initial animations
    $('.header').animate({
        top: '0'
    }, 600);
    
    
//    $('.promo_slider_wrapper_static').animate({
//        opacity: 1.0
//    }, 600);
			
    $('.bottom_wrapper .bottom').animate({
        bottom: '0'
    }, 600, function(){

    	$('.bottom_wrapper .main').css('visibility','visible').animate({
          bottom: '45px'
        }, 800);
    	
    	//        if($('.bottom_wrapper .main').length > 0)
//        {
//        	
//        	$('.bottom_wrapper .main').animate({
//                bottom: '-132px'
//            }, 800, function(){
//                if( $('.promo_slider_wrapper').length > 0 )
//                {
//                	
//                	$('.promo_slider_wrapper').animate({
//                        opacity: 1.0
//                    }, 800);
//                }
//            });
//        }
        
        if($('.bottom_wrapper .content').length > 0)
        {
        	$('.bottom_wrapper .content').css('visibility','visible').animate({
                opacity: 1.0
            }, 800);
        }
    });
    
    
    $('.submenu').each( function() {
        sub_pos(this); 
    });
    
    			
});

$(window).resize(function(){
    $('.submenu').each( function() {
        sub_pos(this); 
    });
    
});


$(document).ready(function(){
        var IE6 = (navigator.userAgent.indexOf("MSIE 6")>=0) ? 1 : 0;
        if ( IE6 === 1 ) {
            $('#footer').append('<a class="ie6" href="/js/x2-IE6/ie6_popup.php?r='+Math.floor(Math.random()*11)+'"></a>');
	    $('a.ie6').fancybox({
                'type'          :'iframe',
                'width'	        : 574,
                'height'	: 300,
                'padding' 	: 0,
                'fitToView'	: false,
                'autoSize'	: false,
                'closeClick'	: false,
                'showCloseButton'    : false,
                'hideOnOverlayClick' : false
            });
           
	    $('.ie6').trigger('click');	
	}
     
});


function sub_pos(objname) {
    var obj = $(objname);
    var screen = $('.wrapper').width() - 15;
    var pos_parent = obj.parent().position();
    var cont_rooms_width = obj.width();
    var cont_rooms_pos = screen - pos_parent.left;
    if ( cont_rooms_width > cont_rooms_pos ) {
        var cont_rooms_d = cont_rooms_width - cont_rooms_pos;
        obj.css('left', -cont_rooms_d);
    //console.log('bigger::'+cont_rooms_d);
    }
}
    




